﻿
using Base.Common.HttpClient;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
 namespace Base.ClientUI {
    public class WCSHttpUtil {
         public static String baseUrl;
        static WCSHttpUtil() {
            baseUrl = ConfigurationManager.AppSettings["wcsServer"];
        }
         protected static List<String> infoList = new List<String>();
        public static void setNetInfo(string info) {
            infoList.Add(DateTime.Now.ToString("HH:mm:ss") + info);
        }
         public static String getNetInfo() {
            String info = null;
             if( infoList.Count > 0 ) {
                String inf = infoList[0];
                 info = "[" + infoList.Count + "]" + inf;
                infoList.RemoveAt(0);
            }
            return info;
        }
        public static JArray getArray( String url) {
            try {
                long begin = DateTime.Now.Ticks;
                JArray obj = WCSClientHttpUtil.getArray(url);
                setNetInfo("["+(DateTime.Now.Ticks-begin)/10000+"ms]"+url);
                return obj;
            } catch( Exception e ) {
                setNetInfo(url + e.Message);
              
            }
            return null;
        }
         public static JObject getObject( String url) {
             try {
                long t = DateTime.Now.Ticks;
                JObject obj= WCSClientHttpUtil.getObject(url);
                setNetInfo("["+(DateTime.Now.Ticks-t)/10000+"ms]"+url);
                return obj;
             } catch( Exception e ) {
                setNetInfo(url + e.Message);
              
            }
        
            return null;
        }
         public static T getEntity<T>(String url)
        {
            try
            {
                T obj = WCSClientHttpUtil.getEntity<T>(url);
                setNetInfo(url);
                return obj;
            }
            catch (Exception e)
            {
                setNetInfo(url + e.Message);
             }
            return default(T);
        }
         public static List<T> getList<T>(String url) {
            try {
                List<T> obj = WCSClientHttpUtil.getList<T>(url);
                setNetInfo(url);
                return obj;
            } catch( Exception e ) {
                setNetInfo(url + e.Message);
             }
            return default(List<T>);
        }
         public static JValue getJValue( String url) {
             try {
                JValue obj = WCSClientHttpUtil.getJValue(url);
                setNetInfo(url);
                return obj;
            } catch( Exception e ) {
                setNetInfo(url+e.Message);
             
            }
             return null;
        }
       }
}
